{extend name="base"}
{block name="title"}
角色管理-分配权限
{/block}
{block name="main"}
<body>
<div class="x-body">
    <form action="" method="post" class="layui-form layui-form-pane">
        <input type="hidden" id="id" value="{$role.id}">
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                <span class="x-red">*</span>角色职称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="name" name="name" id="title" required lay-verify="required" value="{$role.title}"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">
                拥有权限
            </label>
            <table class="layui-table layui-input-block">
                <tbody>
                {volist name="roles" id="vo"}
                <tr>
                    <!--一级分类-->
                    <td width="20%">
                        <div class="layui-input-block">
                            <input name="id[]" type="checkbox"
                            {if condition="in_array($vo['id'],$auth['rules']) "} checked="checked" {/if} value="{$vo.id}"> {$vo.title}
                        </div>
                    </td>
                    <!--二级分类-->
                    {volist name="vo['data']" id="vo1"}
                    <td width="20%">
                        <div class="layui-input-block">
                            <input name="id[]" type="checkbox"
                            {if condition="in_array($vo1['id'],$auth['rules']) "}checked="checked" {/if} value="{$vo1.id}"> {$vo1.title}
                        </div>
                    </td>
                    <!--三级分类-->
                    {volist name="vo1['data']" id="vo2"}
                    <td width="20%">
                        <div class="layui-input-block">
                            <input name="id[]" type="checkbox"
                            {if condition="in_array($vo2['id'],$auth['rules']) "} checked="checked" {/if} value="{$vo2.id}"> {$vo2.title}
                        </div>
                    </td>
                    {/volist}
                    {/volist}
                </tr>
                {/volist}
                </tbody>
            </table>
        </div>
        <div class="layui-form-item layui-form-text">
            <label for="desc" class="layui-form-label">
                备注
            </label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" id="desc" name="desc" class="layui-textarea">具有至高无上的权利</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <button class="layui-btn" lay-submit="" onclick="btn()"  lay-filter="save">保存</button>
        </div>
    </form>
</div>
{/block}
{block name="script"}
<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form()
            , layer = layui.layer;

        //监听提交
        form.on('submit(save)', function (data) {
            //发异步，把数据提交给php
            var obj = $('input[type="checkbox"]:checked');
            var html = [];
            $(obj).each(function(){
                html.push($(this).val());
            });
            //数组转换成字符串
            $arr = html.join(',');
            //转换成对象
            var params = {};
            params.id = $('#id').val();
            params.ids = $arr;
            $.post("{:url('admin/Role/roleUpdate')}",params,function(data){
                console.debug(data);
                if(data==1){
                    layer.alert("增加成功", {icon: 6,time:1000}, function () {
                        // 获得frame索引
                        location.href="{:url('admin/Role/index')}";
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                    });
                }
            });
            return false;
        });
    });
</script>
<script>
    var _hmt = _hmt || [];
    (function () {
        var hm = document.createElement("script");
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();
</script>
{/block}